package GUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import database.TableManager;
import database.TableManager.TableEnum;

public class GUI_page04_DailySalesReport extends JPanel {

	JLabel titleLabel;
	JButton returnButton;
	
	JLabel storeNameLabel;
	List<String> storeOptions;
	JComboBox storeList;
	JLabel dateLabel;
	JTextField dateField;
	
	JTable table;
	JScrollPane scrollPane;
	
	public GUI_page04_DailySalesReport() {
		storeOptions = new ArrayList<String>();
		storeOptions.add("None");
		
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setBackground(Color.white);
		
		// title label
		titleLabel = new JLabel("Daily Sales Report", JLabel.CENTER);
		titleLabel.setVerticalTextPosition(JLabel.CENTER);
		
		titleLabel.setHorizontalTextPosition(JLabel.CENTER);
		titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
		titleLabel.setFont(new Font("Century Gothic", Font.BOLD, 20));
		titleLabel.setForeground(Color.gray);
		this.add(titleLabel);
        
		this.add(Box.createRigidArea(new Dimension(0,15)));

        // return button
		returnButton = GUI_AMSStoreMain.makeGrayWhiteButton("Back", Component.LEFT_ALIGNMENT);
		this.add(returnButton);
        
        this.add(Box.createRigidArea(new Dimension(0,10)));
        
        // store name field
        storeNameLabel = GUI_AMSStoreMain.makeLeftAlignedGrayLabel("Store Name", 11);
        this.add(storeNameLabel);
        // list of stores to choose from, by default on first one
        Object[] tableStrings = storeOptions.toArray();
        storeList = new JComboBox(tableStrings);
        storeList.setSelectedIndex(0);
        storeList.setAlignmentX(Component.LEFT_ALIGNMENT);
        storeList.setForeground(Color.gray);
        storeList.setBackground(Color.white);
        storeList.setFont(new Font("Century Gothic", Font.PLAIN, 13));
        storeList.setMaximumSize(new Dimension(200,20));
        storeList.setSize(new Dimension(200, 20)); 
        this.add(storeList);
		
		this.add(Box.createRigidArea(new Dimension(0,5)));
		
		// date field
		dateLabel = GUI_AMSStoreMain.makeLeftAlignedGrayLabel("Date (yyyy-mm-dd)", 11);
		this.add(dateLabel);
		dateField = GUI_AMSStoreMain.makeLeftGrayTextField("yyyy-mm-dd",80);
		this.add(dateField);
		
		this.add(Box.createRigidArea(new Dimension(0,5)));
		
		scrollPane = new JScrollPane(table);
		this.add(scrollPane);
	}
	
	public void resetPage()
	{
		this.populateTable(null, null);
		this.remove(storeList);
		// list of stores to choose from, by default on first one
        Object[] tableStrings = storeOptions.toArray();
        storeList = new JComboBox(tableStrings);
        storeList.setSelectedIndex(0);
        storeList.setAlignmentX(Component.LEFT_ALIGNMENT);
        storeList.setForeground(Color.gray);
        storeList.setBackground(Color.white);
        storeList.setFont(new Font("Century Gothic", Font.PLAIN, 13));
        storeList.setMaximumSize(new Dimension(200,25));
        storeList.setSize(new Dimension(200, 25));
        this.add(storeList,5);
        
        dateField.setText("yyyy-mm-dd");
	}
	
	
	public void populateTable(Object[] columnNames, Object[][] data){
		this.remove(scrollPane);
		
		if (columnNames == null || data == null)
			scrollPane = new JScrollPane();
		else
		{
			table = new JTable(data, columnNames);
			table.setPreferredScrollableViewportSize(new Dimension(400,70));
			table.setFillsViewportHeight(true);
			scrollPane = new JScrollPane(table);
		}
		this.add(scrollPane, 10);
	}
}
